import router from '@/router'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
export default new Vuex.Store({
  state: {
    userInfo:userInfo
  },
  getters: {
    menuList(state){
      return state.userInfo.menus
    }
  },
  mutations: {
    saveUserInfo(state,info){
      // 保存到vuex
      state.userInfo = info;
      // 保存到本地
      localStorage.setItem('userInfo',JSON.stringify(info))
    },
    // 退出登录时 清空用户信息
    clearUserInfo(){
        // 保存到vuex
        state.userInfo = '';
        // 保存到本地
        localStorage.removeItem('userInfo')
    }
  },
  actions: {
  },
  modules: {
  }
})
